using System;
using System.ComponentModel.Composition;
using System.Linq;
using System.Reactive.Concurrency;
using System.Reactive.Linq;

namespace Boggle.Net.Model
{
    [Export(typeof(ISolver))]
    public class Solver : ISolver
    {
        [Import]
        public IWordList WordList
        {
            get;
            set;
        }

        public IObservable<AcceptablePlay> FindAllWordsIn(Tray tray)
        {
            return tray
                .FindAllWordsIn(WordList)
                .Select(result => new AcceptablePlay(result))
                .OrderBy(acceptablePlay => acceptablePlay.Word)
                .ToObservable(Scheduler.ThreadPool)
                .ObserveOnDispatcher();
        }
    }
}